package dao;

import java.util.List;

import model.Tipopromocao;

import org.hibernate.Criteria;
import org.hibernate.Session;

import org.hibernate.Transaction;

import util.HibernateUtil;

public class TipoPromocaoDAO {
    public TipoPromocaoDAO() {
        session = HibernateUtil.getSessionFactory().openSession();
    }
    
    private Session session;
    
    public void insert(Tipopromocao tp){
        Transaction t = session.beginTransaction();
        session.merge(tp);
        t.commit();
    }
    
    public void delete(Tipopromocao tp){
        Transaction t = session.beginTransaction();
        session.delete(tp);
        t.commit();
    }
    
    public List<Tipopromocao> findAll(){
        Criteria criteria = session.createCriteria(Tipopromocao.class);
        return criteria.list();
    }
    
    public static void main(String[] args) {
        TipoPromocaoDAO tpDAO = new TipoPromocaoDAO();
        for (Tipopromocao tp : tpDAO.findAll()){
            System.out.println(tp.getDescricao());
        }
    }
}
